package com.doit.day01;

import lombok.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class _比较器 {
    public static void main(String[] args) {
        ArrayList<OrderInfo> list = new ArrayList<>();
        list.add(new OrderInfo("o001", "sn001", "g001", "c001", 2, 9.9));
        list.add(new OrderInfo("o002", "sn002", "g002", "c002", 1, 1400.0));
        list.add(new OrderInfo("o003", "sn003", "g003", "c003", 3, 189.0));
        list.add(new OrderInfo("o005", "sn005", "g005", "c005", 1, 2008.0));
        list.add(new OrderInfo("o004", "sn004", "g004", "c004", 54, 800.0));
        list.add(new OrderInfo("o008", "sn008", "g008", "c008", 3, 356.0));
        list.add(new OrderInfo("o007", "sn007", "g007", "c007", 8, 19.9));
        list.add(new OrderInfo("o006", "sn006", "g006", "c006", 1, 39.9));

        //将集合里面所有的orderInfo 排个序
        Collections.sort(list);

        for (OrderInfo orderInfo : list) {
            System.out.println(orderInfo);
        }

        /**
         * 想要比较一个东西
         * 要么这个东西是可以比较的
         * 要么比较的时候，传一个比较器给他
         *
         * 比较规则
         */

        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(3);
        list1.add(2);
        list1.add(9);
        list1.add(4);
        list1.add(5);
        list1.add(8);

        //int   double   string 这些类型的值，天生就是可以比较的  实现了 comparable 接口
        Collections.sort(list1);
        System.out.println(list1);


    }
}

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
class OrderInfo implements Comparable<OrderInfo>{
    private String order_id;
    private String order_sn;
    private String goods_id;
    private String category_id;
    private int goods_number;
    private Double price;

    @Override
    public int compareTo(OrderInfo o) {
        return Double.compare(o.price,this.price);
    }
}
